package com.party.admin.web.controller.notify;

import com.google.common.base.Strings;
import com.party.admin.web.dto.input.notify.ClAcceptInput;
import com.party.core.model.notify.Instance;
import com.party.core.service.notify.IInstanceService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * 创蓝短信处理控制器
 * Created by wei.li
 *
 * @date 2017/4/11 0011
 * @time 15:43
 */

@Controller
@RequestMapping(value = "notify/cl")
public class ClMessageController {

    protected static Logger logger = LoggerFactory.getLogger(ClMessageController.class);

    @Autowired
    private IInstanceService instanceService;


    /**
     * 推送结果接受
     * @param input
     */
    @RequestMapping(value = "acceptNotify")
    public void acceptNotify(ClAcceptInput input){
        logger.info("创蓝短信结果推送{}", input.toString());

        if (!Strings.isNullOrEmpty(input.getMsgid())
                && !Strings.isNullOrEmpty(input.getStatus())){

            Instance instance = instanceService.findByMsgId(input.getMsgid());
            if (null == instance){
                return;
            }

            if (Strings.isNullOrEmpty(instance.getStatus())){
                instance.setStatus(input.getStatus());
                instanceService.update(instance);
            }
        }
    }
}
